﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetSysData;
namespace BladeTecWebApplication.Admin
{
    public partial class EditPosition : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int position_id;
                //GetPositionList_Result[] position_details;
                POSITION position;
                NetSysData.NetSysData data = new NetSysData.NetSysData();
                QUIZ[] quizzes = data.GetQuizzes();

                try
                {
                    position_id = Int32.Parse(Request.QueryString["position_id"]);
                }
                catch (Exception)
                {
                    // show error
                    return;
                }

                
             

                position = data.GetPosition(position_id);
                if (position == null)
                {
                    //show error
                    return;
                }
                ddlQuiz.Items.Add(new ListItem("Select ...", ""));
				foreach (QUIZ quiz in quizzes)
				{
					ddlQuiz.Items.Add(new ListItem(quiz.QUIZ_NAME, quiz.QUIZ_ID.ToString()));
				}

                txtPositionTitle.Text = position.POSITION_TITLE;
                ddlQuiz.SelectedIndex = position.QUIZ_ID;

                hireDate.Value = position.HIRE_DATE.ToString();
                DateTime dt = Convert.ToDateTime(hireDate.Value);
                hireDate0.Value = dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString();
                hfpositionID.Value = position.POSITION_ID.ToString();
               


                
            }
        }

        protected void btnAddPosition_Click(object sender, EventArgs e)
        {
            NetSysData.NetSysData data = new NetSysData.NetSysData();

            POSITION p = data.GetPosition(Int32.Parse(hfpositionID.Value));

            p.POSITION_TITLE = txtPositionTitle.Text;
            p.QUIZ_ID = ddlQuiz.SelectedIndex;
            p.HIRE_DATE = DateTime.Parse(hireDate.Value);

            data.Save();

           lblTitle.Text = p.POSITION_TITLE;

           DateTime dt = Convert.ToDateTime(hireDate.Value);
           hireDate0.Value = dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString();

           lblHireDate.Text = hireDate0.Value;


            pnlPositionForm.Visible = false;
            pnlConfirmationForm.Visible = true;
        }
    }
}